#外层循环执行一次，内层循环执行多次
#外层循环控制行，内层循环控制列
for r in range(2):
    for c in range(5):
        print("*",end=" ")
    print()


for i in range(4):
    for j in range(i+1):
        print("$",end=" ")
    print()

"""
    二维列表
        列表名[行索引][列索引]
"""
list01 = [
    [1,2,3,4,5],
    [6,7,8,9,10],
    [11,12,13,14,15]
]

for a in range(len(list01[0])):
    print(list01[0][a])

for c in range(len(list01[1])):
    print(list01[1][-(c+1)])

print(len(list01))
for b in range(len(list01)):
    print(list01[b][0])

for d in range(len(list01)):
    print(list01[-(d+1)][4])

for r in range(len(list01)):
    for c in range(len(list01[r])):
        print(list01[r][c],end="\t")
    print()

for line in list01:
    for item in line:
        print(item,end="\t")
    print()

dict_travel_info = {
    "北京": {
        "景区": ["长城","故宫"],
        "美食": ["烤鸭","豆汁焦圈","炸酱面"]
    },
    "四川": {
        "景区": ["九寨沟","峨眉山"],
        "美食": ["火锅","兔头"]
    }
}

for item in dict_travel_info["北京"]["景区"]:
    print(item)

print(dict_travel_info["四川"]["美食"][1])

for item in dict_travel_info["北京"]["美食"]:
    print(item)

for values in dict_travel_info.values():
    for item in values["美食"]:
        print(item)

"""
    小结 - 算法
        1. 循环计数
            开始
            for/while...
                间隔
        2. 交换
            a,b = b,a
        3.最值
"""
list01 = [5,65,76,87,89,9]

for r in range(len(list01)-1):
    for c in range(r+1,len(list01)):
        if list01[r] < list01[c]:
            list01[r],list01[c] = list01[c],list01[r]
print(list01)

# 练习：对数字列表进行升序排列
for r in range(len(list01)-1):
    for c in range(r+1,len(list01)):
        if list01[r] > list01[c]:
            list01[r],list01[c] = list01[c],list01[r]
print(list01)

# 商品字典
# 1.打印所有商品信息，格式：商品编号xx,商品名称xx,商品单价xx.
dict_commodity_infos = {
    1001: {"name":"屠龙刀","price":10000},
    1002: {"name":"倚天剑","price":10000},
    1003: {"name":"金箍棒","price":52100},
    1004: {"name":"口罩","price":20},
    1005: {"name":"酒精","price":30}
}

list_orders = [
    {"cid":1001,"count":1},
    {"cid":1002,"count":3},
    {"cid":1005,"count":2},
]

for k,v in dict_commodity_infos.items():
    print("商品编号:%s,商品名称：%s,商品单价：%s." %(k,v["name"],v["price"]))

# 2.打印所有订单的信息，格式：商品编号xx,购买数量xx.
for item in list_orders:
    # print(item)
    print("商品编号%s,购买数量%s" %(item["cid"],item["count"]))

# 3.打印所有订单中的商品信息，格式：商品名称xx,商品单价：xx,数量xx.
for key in dict_commodity_infos:
    for index in range(len(list_orders)):
        if key == list_orders[index]["cid"]:
            print("商品名称%s,商品单价：%s,数量%s" %(dict_commodity_infos[key]["name"],dict_commodity_infos[key]["price"],list_orders[index]["count"]))

for item in list_orders:
    cid = item["cid"]
    commodity = dict_commodity_infos[cid]
    print(f"商品名称{commodity['name']},商品单价：{commodity['price']},数量{item['count']}")

# 4.查找数量最多的订单（使用自定义算法，不适用内置函数）
max_cid = list_orders[0]["cid"]
max_count = list_orders[0]["count"]
for index in range(1,len(list_orders)):
    if max_count < list_orders[index]["count"]:
        max_cid = list_orders[index]["cid"]
        max_count = list_orders[index]["count"]
print(f"数量订单为：{max_cid},订单数量为：{max_count}")

# 5.根据购买数量对订单列表降序（大->小）排列
for index in range(len(list_orders)-1):
    for j in range(index+1,len(list_orders)):
        if list_orders[index]["count"] < list_orders[j]["count"]:
            list_orders[index],list_orders[j] = list_orders[j],list_orders[index]
print(list_orders)

list01 = ["香蕉","苹果","哈密瓜"]
list02 = ["雪碧","牛奶","咖啡","果汁"]
list_new = []
for r in list01:
    for c in list02:
        list_new.append((r,c))
print(list_new)
list_new = [ (r,c) for r in list01 for c in list02 ]
print(list_new)

#练习1：请排列出2个色子range(1,7)的所有组合
for i in range(1,7):
    for j in range(1,7):
        print(i,j)
#练习2：请排列出3个色子range(1,7)的所有组合
for i in range(1,7):
    for j in range(1,7):
        for k in range(1,7):
            print(i,j,k)